import http from '@/common/api/request'
import {getToken} from '@/request/token'

export function getArticle(page){
  return http.$axios({
    url:"article",
    method:"post",
    data:{
      page: page.pageNumber,
      pageSize: page.pageSize,
      name: page.name,
      sortId: page.sortId,
      findMsg:page.findMsg,
      // year: query.year,
      // month: query.month,
      tagId: page.tagId,
      // categoryId: query.categoryId
    }
  })
}

export function hotArticle(){
  return http.$axios({
    url:"article/hotArticle"
  })
}

export function newArticle(){
  return http.$axios({
    url:"article/newArticle"
  })
}

export function publish(article){
  return http.$axios({
    url:'/article/publish',
    method:'post',
    headers:{
      token:getToken()
    },
    data:{
      userId:article.userId,
      title:article.title,
      content:article.content,
      contentHtml:article.contentHtml,
      sortId:article.sortId,
      tags:article.tags
    }
  })
}

export function findArticleById(id){
  return http.$axios({
    url:'/article/'+id,
    method:'post',
  })
}

export function findUserArticle(id){
 
  return http.$axios({
    url:'/article/findUserArticle?id='+id,
    method:'post'

  })
}

export function deleteArticleById(id){
  return http.$axios({
    headers:{
      token:getToken()
    },
    url:'/article/delete/'+id,
    method:'post'
  })
}

export function updateArticle(article){
  return http.$axios({
    url:'/article/update',
    method:'post',
    headers:{
      token:getToken()
    },
    data:{
      id:article.id,
      userId:article.userId,
      title:article.title,
      content:article.content,
      contentHtml:article.contentHtml,
      sortId:article.sortId,
      tags:article.tags
    }
  })
}